package com.burgeon.backend.service.Impl;
/**
 * 微信消息模板  异常直接抛出
 */

import com.burgeon.backend.Rest.Template.Reviews.CreateReviews;
import com.burgeon.backend.Rest.Template.Reviews.FindReviews;
import com.burgeon.backend.SHOP.entity.recharge.ResultRecharge;
import com.burgeon.backend.SHOPBACKEND.entity.HuoTemplate;
import com.burgeon.backend.WeChat.WeChatMessageConnector;
import com.burgeon.backend.entity.*;
import com.burgeon.backend.mappers.AccountMapper;
import com.burgeon.backend.mappers.CouponMapper;
import com.burgeon.backend.mappers.TemplateMapper;
import com.burgeon.backend.mappers.UserMapper;
import com.burgeon.backend.service.MessageTemplateService;
import com.burgeon.backend.service.WechatService;
import com.burgeon.backend.service.ex.ErrorDataException;
import com.burgeon.backend.service.ex.RepetitionException;
import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class MessageTemplateServiceImpl implements MessageTemplateService {

    @Autowired
    private WeChatMessageConnector weChatMessageConnector;
    @Autowired
    private WechatService wechatService;
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private TemplateMapper templateMapper;
    @Autowired
    private CouponMapper couponMapper;
    @Autowired
    private AccountMapper accountMapper;

    /**
     * 会员升降级
     * @param code
     * @param time
     * @param oldType
     * @param newType
     * @param account
     */
    @Override
    public void vipUpgrade(String openid,String code, String time, String oldType, String newType, String account){
        String accessToken = wechatService.GetAccesTokenByAccount(account);
        String url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken;
        String templateId = templateMapper.FindTemplate(account).getTemplateid12();
        Membership membership = new Membership();
        membership.setCode(code);
        membership.setOpenid(openid);
        membership.setNewType(newType);
        membership.setOldType(oldType);
        membership.setTime(time);
        String data = MessageDataForvipUpgrade(membership, templateId);

        String str = weChatMessageConnector.Send(url, data);
        System.err.println(str);

        


    }
    private String MessageDataForvipUpgrade(Membership data, String templateId) {

        return "{  \"touser\":\"" + data.getOpenid() + "\",\n" +
                "           \"template_id\":\"" + templateId + "\",\n" +
                // "           \"url\":\"" + url + "\",  \n" +
                "           \"data\":{\n" +
                "                   \"first\": {\n" +
                "                       \"value\":\"尊敬的客户，您的本次服务已经完成" +"\",\n" +
                "                       \"color\":\"#173177\"\n" +
                "                   },\n" +
                "                   \"keyword1\":{\n" +
                "                       \"value\":\"" + data.getCode() + "\",\n" +
                "                       \"color\":\"#173177\"\n" +
                "                   },\n" +
                "                   \"keyword2\": {\n" +
                "                       \"value\":\"" + data.getTime() + "\",\n" +
                "                        \"color\":\"#173177\"\n" +
                "                   },\n" +
                "                   \"remark\":{\n" +
                "                       \"value\":\"感谢您对我们的支持，欢迎您下次光临！\",\n" +
                "                       \"color\":\"#173177\"\n" +
                "                   } }   }";
    }

    @Override
    public void ReviewsExist(String rcode, String account) throws RepetitionException {

        Info info = accountMapper.GetAccData(account);
        FindReviews findReviews = new FindReviews(info.getUrl(),info.getAccount(),info.getPassword());
        try {
            findReviews.getData(rcode);
        } catch (Exception e) {
            throw new RepetitionException();
        }
    }

    /**
     * 消费提醒
     * 记录要和消费评价分开 因此code的后边加 '_e"
     * @throws ErrorDataException
     */
    @Override
    public void SendMessageForExpenditure(String account,RetailData rdata) throws ErrorDataException {
        if (templateMapper.FindRecordByCode(rdata.getCode()+"_e",account)!=null){//查到相同数据不发送
            return;
        }

        String accessToken = wechatService.GetAccesTokenByAccount(account);
        String url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken;
        String templateId = templateMapper.FindTemplate(account).getTemplateid5();
        //Wechat wechat = wechatService.GetWechatByAccount(account);

        //String SkipUrl = wechat.getRedirectUrl() + "/user/reviews.html?code=" + code + "&phone=" + phone+"&account="+account;

        String data = MessageDataForExpenditure(rdata,templateId);
        String str = weChatMessageConnector.Send(url, data);
        System.err.println(str);
        try {
            JSONObject jsonObject = new JSONObject(str);
            String errcode = jsonObject.getString("errcode");
            if (!"0".equals(errcode)) {
                throw new Exception(str);
            }

            TemplateRecord templateRecord = new TemplateRecord();
            templateRecord.setCode(rdata.getCode()+"_e");
            templateRecord.setType("消费提醒");
            templateRecord.setPhone(rdata.getPhone());
            templateRecord.setOpenid(rdata.getOpenid());
            templateRecord.setAccount(account);
            templateRecord.setState("成功");
            templateMapper.addRecord(templateRecord);

        } catch (Exception e) {
            throw new ErrorDataException(e.getMessage());
        }
    }

    //消费评价模板
    @Override
    public void SendMessageForConsumption(String account, String openid, String code,String phone,String date) throws ErrorDataException {

        if (templateMapper.FindRecordByCode(code,account)!=null){//查到相同数据不发送
            return;
        }

        String accessToken = wechatService.GetAccesTokenByAccount(account);
        String url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken;
        String templateId = templateMapper.FindTemplate(account).getTemplateid2();
        Wechat wechat = wechatService.GetWechatByAccount(account);

        String SkipUrl = wechat.getRedirectUrl() + "/user/reviews.html?code=" + code + "&phone=" + phone+"&account="+account;

        String data = MessageDataForConsumption(openid,templateId,date,code,SkipUrl);
        String str = weChatMessageConnector.Send(url, data);

        try {
            JSONObject jsonObject = new JSONObject(str);
            String errcode = jsonObject.getString("errcode");
            if (!"0".equals(errcode)) {
                throw new Exception(str);
            }

            TemplateRecord templateRecord = new TemplateRecord();
            templateRecord.setCode(code);
            templateRecord.setType("消费评价");
            templateRecord.setPhone(phone);
            templateRecord.setOpenid(openid);
            templateRecord.setAccount(account);
            templateRecord.setState("成功");
            templateMapper.addRecord(templateRecord);
        } catch (Exception e) {
            throw new ErrorDataException(e.getMessage());
        }
    }

    @Override
    public void SendMessageForRecharge(String account,RechargeData rdata) throws ErrorDataException {
        if (templateMapper.FindRecordByCode(rdata.getCode(),account)!=null){//查到相同数据不发送
            return;
        }
        String accessToken = wechatService.GetAccesTokenByAccount(account);
        System.err.println(accessToken);
        String url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken;
        String templateId = templateMapper.FindTemplate(account).getTemplateid4();
        Wechat wechat = wechatService.GetWechatByAccount(account);

        //String SkipUrl = wechat.getRedirectUrl() + "/user/reviews.html?code=" + code + "&phone=" + phone+"&account="+account;

        String data = MessageDataForRecharge(rdata,templateId);
        String str = weChatMessageConnector.Send(url, data);
        System.err.println(str);
        try {
            JSONObject jsonObject = new JSONObject(str);
            String errcode = jsonObject.getString("errcode");
            if (!"0".equals(errcode)) {
                throw new Exception(str);
            }

            TemplateRecord templateRecord = new TemplateRecord();
            templateRecord.setCode(rdata.getCode());
            templateRecord.setType("充值提醒");
            templateRecord.setPhone(rdata.getPhone());
            templateRecord.setOpenid(rdata.getOpenid());
            templateRecord.setAccount(account);
            templateRecord.setState("成功");
            templateMapper.addRecord(templateRecord);

        } catch (Exception e) {
            throw new ErrorDataException(e.getMessage());
        }
    }

    @Override
    public void SendMessageForAppRecharge(String account, ResultRecharge rdata) throws ErrorDataException {
        String accessToken = wechatService.GetAccesTokenByAccount(account);
        System.err.println(accessToken);
        String url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken;
        String templateId = templateMapper.FindTemplate(account).getTemplateid4();
        String data = MessageDataForAppRecharge(rdata,templateId);
        String str = weChatMessageConnector.Send(url, data);
        System.err.println(str);
        try {
            JSONObject jsonObject = new JSONObject(str);
            String errcode = jsonObject.getString("errcode");
            if (!"0".equals(errcode)) {
                throw new Exception(str);
            }

            TemplateRecord templateRecord = new TemplateRecord();
            templateRecord.setCode(rdata.getCode());
            templateRecord.setType("充值提醒");
            templateRecord.setPhone(rdata.getPhone());
            templateRecord.setOpenid(rdata.getOpenid());
            templateRecord.setAccount(account);
            templateRecord.setState("成功");
            templateMapper.addRecord(templateRecord);
        } catch (Exception e) {
            throw new ErrorDataException(e.getMessage());
        }
    }

    //新会员领积分
    @Override
    public void SendMessageForNewUser(String token, String openid, String phone, String integral, String name) throws ErrorDataException {
        String accessToken = wechatService.GetAccesToken(token);
        String url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken;
        //新人领积分
        String templateId = templateMapper.FindTemplate(accountMapper.GetAccountForToken(token)).getTemplateid1();

        Date now = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd HH:mm:ss");
        String dateString = sdf.format(now);
        /*String SkipUrl = "http://lfwd.cloudsmicro.com/user/skip.html?token="+token;*/
        String appId = wechatService.findAppId(token);//小程序的appId
        String data = MessageDataForNewUser(openid, templateId, phone, dateString, integral,appId);
        String str = weChatMessageConnector.Send(url, data);
//        System.err.println("新用户送积分模板========================="+data);
        System.err.println(str);
        try {
            JSONObject jsonObject = new JSONObject(str);
            String errcode = jsonObject.getString("errcode");
            if (!"0".equals(errcode)) {
                throw new Exception(str);
            }

            TemplateRecord templateRecord = new TemplateRecord();
            templateRecord.setCode(integral);
            templateRecord.setType("新会员送积分");
            templateRecord.setPhone(phone);
            templateRecord.setOpenid(openid);
            templateRecord.setToken(token);
            templateRecord.setState("成功");
            templateMapper.addRecord(templateRecord);
        } catch (Exception e) {
            throw new ErrorDataException(e.getMessage());
        }
    }
    //优惠券模板
    @Override
    public void SendMessageForCoupon(String account, String phone, String code, String price, String discount, String type) throws ErrorDataException {
        User user = userMapper.FindUserDataByPhone(phone, account);
        if (user == null) {
            return;
        }
        String accessToken = wechatService.GetAccesTokenByAccount(account);
        String url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken;
        String templateId = templateMapper.FindTemplate(account).getTemplateid();
        /*Wechat wechat = wechatService.GetWechatByAccount(account);
        String SkipUrl = wechat.getRedirectUrl() + "/user/user-coupon-item.html?account=" + account + "&code=" + code;*/
        String appId = wechatService.findAppId(account);//小程序的appId
        String value;
        if ("VOU4".equals(type)) {
            type = "折扣";
            value = discount + "折";
        } else {
            type = "金额";
            value = price + "元";

        }
        String data = MessageDataForCoupon(user.getOpenid(), templateId, code, value, user.getName(), appId, type);
//        System.err.println("优惠券===================================="+data);
        String str = weChatMessageConnector.Send(url, data);
        System.err.println(str);
        try {
            JSONObject jsonObject = new JSONObject(str);
            String errcode = jsonObject.getString("errcode");
            if (!"0".equals(errcode)) {
                throw new Exception(str);
            }

            TemplateRecord templateRecord = new TemplateRecord();
            templateRecord.setCode(code);
            templateRecord.setType("购物券");
            templateRecord.setPhone(phone);
            templateRecord.setOpenid(user.getOpenid());
            templateRecord.setAccount(account);
            templateRecord.setState("成功");
            templateMapper.addRecord(templateRecord);
        } catch (Exception e) {
            System.err.println(e.getMessage());
            throw new ErrorDataException(e.getMessage());
        }
    }

    @Override
    public Coupon GenCouponItem(String account, String code) {
        Coupon data = couponMapper.FindCouponByCode(code, account);
        if (data.getTypeid() != null) {
            data.setExpl(couponMapper.findCouponTypeById(data.getTypeid()).getExpl());
        }
        return data;
    }

    @Override
    public Template GetTemplate(String account) {
        return templateMapper.FindTemplate(account);
    }

    @Override
    public void UpDataTemplate(Template template) throws ErrorDataException {
        if (null ==template.getAccount()){
            return;
        }
        if (templateMapper.FindTemplate(template.getAccount()) == null) {
            Integer row = templateMapper.NewTemplate(template);
            if (row != 1) {
                throw new ErrorDataException("添加失败");
            }
            return;
        }
        Integer row = templateMapper.UpDataTemplate(template);
        if (row != 1) {
            throw new ErrorDataException("修改失败");
        }
    }

    @Override
    public void CreateConsumptionBos(Reviews reviews,String account) throws ErrorDataException {
        System.err.println(account);
        Info info = accountMapper.GetAccData(account);
        CreateReviews createReviews = new CreateReviews(info.getUrl(),info.getAccount(),info.getPassword());
        try {
            createReviews.getData(reviews);
        } catch (Exception e) {
            throw new ErrorDataException(e.getMessage());
        }
    }

    /**推荐新用户送积分*/
    @Override
    public void SendMessageForRecommend(String token, String openid, String phone, String integral, String name) throws ErrorDataException {
        String accessToken = wechatService.GetAccesToken(token);
        String url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken;
        //推荐新人领积分
        String templateId = templateMapper.FindTemplate(accountMapper.GetAccountForToken(token)).getTemplateid1();

        Date now = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd HH:mm:ss");
        String dateString = sdf.format(now);
        String SkipUrl = "http://lfwd.cloudsmicro.com/user/skip.html?token="+token;

        String data = MessageDataForRecommend(openid, templateId, phone, dateString, integral,SkipUrl);
        String str = weChatMessageConnector.Send(url, data);
        System.err.println("推荐新用户送积分模板");
        System.err.println(str);
        try {
            JSONObject jsonObject = new JSONObject(str);
            String errcode = jsonObject.getString("errcode");
            if (!"0".equals(errcode)) {
                throw new Exception(str);
            }

            TemplateRecord templateRecord = new TemplateRecord();
            templateRecord.setCode(integral);
            templateRecord.setType("推荐新会员送积分");
            templateRecord.setPhone(phone);
            templateRecord.setOpenid(openid);
            templateRecord.setToken(token);
            templateRecord.setState("成功");
            templateMapper.addRecord(templateRecord);
        } catch (Exception e) {
            throw new ErrorDataException(e.getMessage());
        }
    }

    @Override
    public void SendMessageForActivity(String account,String openid, String templateId,String first,String keyword1,
                                       String keyword2, String keyword3,String keyword4,String remark) {
        String token = accountMapper.GetTokenForAccount(account);
//        String account = accountMapper.GetAccountForToken(token);
        String accessToken = wechatService.GetAccesToken(token);
        String url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken;
        HuoTemplate template = templateMapper.FindHuoTemplate(account);

            templateId=template.getTemplateid7();
            String data = MessageForActivity2(first, openid, keyword1, keyword2, keyword3, keyword4, templateId, remark);
            String str = weChatMessageConnector.Send(url, data);
            System.err.println("活动内容模板:"+str);


    }
    @Override
    public void SendMessageForYY(String account,String openid, String templateId,String first,String keyword1,
                                       String keyword2, String keyword3,String remark) {
        String token = accountMapper.GetTokenForAccount(account);
//        String account = accountMapper.GetAccountForToken(token);
        String accessToken = wechatService.GetAccesToken(token);
        String url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken;
        HuoTemplate template = templateMapper.FindHuoTemplate(account);

            templateId=template.getTemplateid6();
            System.err.println(templateId);
            String data = MessageForActivity1(first,openid,keyword1,keyword2,keyword3,templateId,remark);
            System.err.println(data);
            String str = weChatMessageConnector.Send(url, data);
            System.err.println("活动内容模板:"+str);


    }

    @Override
    public boolean SendExpiredCouponTemplate(String templateId,String token, String code, String money, String expiredTime, String openid) {
        String accessToken = wechatService.GetAccesToken(token);
        String url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken;
        String first="您有1张优惠券即将到期，为避免影响您的正常享受优惠福利，劳烦尽快使用";
        String cause= "即将到期";
        String remark = "感谢您的光临。";
//        openid="ocqj9w1La0t07ziB6v62qupSIidY";
        String data = ExpiredCouponTemplate(first,openid,code,money,expiredTime,cause,templateId,remark);
        System.err.println(data);
        String str = weChatMessageConnector.Send(url, data);
        System.err.println("活动内容模板:"+str);
        JSONObject jsonObject = null;
        try {
            jsonObject = new JSONObject(str);
            if("0".equals(jsonObject.getString("errcode"))) {
                return true;
            }
        } catch (JSONException e) {
//            e.printStackTrace();

        }
        return false;
    }

    //查询模板消息列表
    @Override
    public List<TemplateRecord> findMessageRecord(String account,String phone,String flag,String startTime,String endTime) {
        List<TemplateRecord> data = templateMapper.findMessageRecord(account,phone,flag,startTime,endTime);
        return data;
    }

    @Override
    public void SendExtractMessageTemplate(String openid,String goodsName,String sinceDate, String xsno, String selfRaiNo, String store, String address, String account) {
        String accessToken = wechatService.GetAccesToken(account);
        String url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken;
        String templateId = templateMapper.FindHuoTemplate(account).getTemplateid10();
        String first = "商品："+goodsName+",待提取";
        String remark = "期待您的光临";
        String storeAddress = "店铺："+store+"，详细地址："+address;
        String data = MessageForExtractMessage(first,openid,sinceDate,xsno,selfRaiNo,storeAddress,templateId,remark);
        System.err.println(data);
        String str = weChatMessageConnector.Send(url, data);
        System.err.println(str);

    }

    private String MessageForExtractMessage(String first, String openid, String sinceDate, String xsno, String selfRaiNo, String storeAddress,
                                            String templateId, String remark){

        return "{  \"touser\":\"" + openid + "\",\n" +
                "           \"template_id\":\"" + templateId + "\",\n" +
                "           \"data\":{\n" +
                "                   \"first\": {\n" +
                "                       \"value\":\""+first +"\",\n" +
                "                       \"color\":\"#173177\"\n" +
                "                   },\n" +
                "                   \"keyword1\":{\n" +
                "                       \"value\":\"" + xsno + "\",\n" + //订单号
                "                       \"color\":\"#173177\"\n" +
                "                   },\n" +
                "                   \"keyword2\": {\n" +
                "                       \"value\":\"" + selfRaiNo + "\",\n" + //自提码
                "                        \"color\":\"#173177\"\n" +
                "                   },\n" +
                "                   \"keyword3\": {\n" +
                "                       \"value\":\"" + sinceDate + "\",\n" + //自提时间
                "                        \"color\":\"#173177\"\n" +
                "                   },\n" +
                "                   \"keyword4\": {\n" +
                "                       \"value\":\"" + storeAddress + "\",\n" + //自提地点
                "                        \"color\":\"#173177\"\n" +
                "                   },\n" +
                "                   \"remark\":{\n" +
                "                       \"value\":\""+remark+"\",\n" +
                "                       \"color\":\"#173177\"\n" +
                "                   } }   }";
    }

    private String ExpiredCouponTemplate(String first, String openid, String code, String money, String expiredTime,
                                         String cause,String templateId, String remark) {
        return "{  \"touser\":\"" + openid + "\",\n" +
                "           \"template_id\":\"" + templateId + "\",\n" +
                "           \"data\":{\n" +
                "                   \"first\": {\n" +
                "                       \"value\":\""+first +"\",\n" +
                "                       \"color\":\"#173177\"\n" +
                "                   },\n" +
                "                   \"keyword1\":{\n" +
                "                       \"value\":\"" + code + "\",\n" + //消费门店
                "                       \"color\":\"#173177\"\n" +
                "                   },\n" +
                "                   \"keyword2\": {\n" +
                "                       \"value\":\"" + money + "\",\n" + //订单编号
                "                        \"color\":\"#173177\"\n" +
                "                   },\n" +
                "                   \"keyword3\": {\n" +
                "                       \"value\":\"" + expiredTime + "\",\n" + //订单状态
                "                        \"color\":\"#173177\"\n" +
                "                   },\n" +
                "                   \"keyword4\": {\n" +
                "                       \"value\":\"" + cause + "\",\n" + //门店地址
                "                        \"color\":\"#173177\"\n" +
                "                   },\n" +
                "                   \"remark\":{\n" +
                "                       \"value\":\""+remark+"\",\n" +
                "                       \"color\":\"#173177\"\n" +
                "                   } }   }";
    }

    private String MessageForActivity1(String first, String openid, String keyword1, String keyword2,
                                       String keyword3,String templateId,String remark) {
        return "{  \"touser\":\"" + openid + "\",\n" +
                "           \"template_id\":\"" + templateId + "\",\n" +
                "           \"data\":{\n" +
                "                   \"first\": {\n" +
                "                       \"value\":\""+first +"\",\n" +
                "                       \"color\":\"#173177\"\n" +
                "                   },\n" +
                "                   \"keyword1\":{\n" +
                "                       \"value\":\"" + keyword1 + "\",\n" + //
                "                       \"color\":\"#173177\"\n" +
                "                   },\n" +
                "                   \"keyword2\": {\n" +
                "                       \"value\":\"" + keyword2 + "\",\n" + //金额
                "                        \"color\":\"#173177\"\n" +
                "                   },\n" +
                "                   \"keyword3\": {\n" +
                "                       \"value\":\"" + keyword3 + "\",\n" + //充值赠送
                "                        \"color\":\"#173177\"\n" +
                "                   },\n" +
                "                   \"remark\":{\n" +
                "                       \"value\":\""+remark+"\",\n" +
                "                       \"color\":\"#173177\"\n" +
                "                   } }   }";
    }
    private String MessageForActivity2(String first, String openid, String keyword1, String keyword2,
                                       String keyword3,String keyword4,String templateId,String remark) {
        return "{  \"touser\":\"" + openid + "\",\n" +
                "           \"template_id\":\"" + templateId + "\",\n" +
                //     "           \"url\":\"" + url + "\",  \n" +
                "           \"data\":{\n" +
                "                   \"first\": {\n" +
                "                       \"value\":\""+first +"\",\n" +
                "                       \"color\":\"#173177\"\n" +
                "                   },\n" +
                "                   \"keyword1\":{\n" +
                "                       \"value\":\"" + keyword1 + "\",\n" + //
                "                       \"color\":\"#173177\"\n" +
                "                   },\n" +
                "                   \"keyword2\": {\n" +
                "                       \"value\":\"" + keyword2 + "\",\n" + //金额
                "                        \"color\":\"#173177\"\n" +
                "                   },\n" +
                "                   \"keyword3\": {\n" +
                "                       \"value\":\"" + keyword3 + "\",\n" + //充值赠送
                "                        \"color\":\"#173177\"\n" +
                "                   },\n" +
                "                   \"keyword4\": {\n" +
                "                       \"value\":\"" + keyword4 + "\",\n" + //充值赠送
                "                        \"color\":\"#173177\"\n" +
                "                   },\n" +
                "                   \"remark\":{\n" +
                "                       \"value\":\""+remark+"\",\n" +
                "                       \"color\":\"#173177\"\n" +
                "                   } }   }";
    }
    private String MessageDataForRecharge(RechargeData data,String templateId) {

        return "{  \"touser\":\"" + data.getOpenid() + "\",\n" +
                "           \"template_id\":\"" + templateId + "\",\n" +
                //     "           \"url\":\"" + url + "\",  \n" +
                "           \"data\":{\n" +
                "                   \"first\": {\n" +
                "                       \"value\":\"您的会员卡充值金额已实时到账，请查收" +"\",\n" +
                "                       \"color\":\"#173177\"\n" +
                "                   },\n" +
                "                   \"keyword1\":{\n" +
                "                       \"value\":\"" + data.getDate() + "\",\n" + //时间
                "                       \"color\":\"#173177\"\n" +
                "                   },\n" +
                "                   \"keyword2\": {\n" +
                "                       \"value\":\"" + data.getPrice() + "\",\n" + //金额
                "                        \"color\":\"#173177\"\n" +
                "                   },\n" +
                "                   \"keyword3\": {\n" +
                "                       \"value\":\"" + "现金" + "\",\n" + //方式
                "                        \"color\":\"#173177\"\n" +
                "                   },\n" +
                "                   \"keyword4\": {\n" +
                "                       \"value\":\"" + data.getGive() + "\",\n" + //充值赠送
                "                        \"color\":\"#173177\"\n" +
                "                   },\n" +
                "                   \"keyword5\": {\n" +
                "                       \"value\":\"" + data.getBalance() + "\",\n" + //当前余额
                "                        \"color\":\"#173177\"\n" +
                "                   },\n" +
                "                   \"remark\":{\n" +
                "                       \"value\":\"感谢您选购我们的产品和服务，您的满意是我们始终不变的追求！\",\n" +
                "                       \"color\":\"#173177\"\n" +
                "                   } }   }";
    }

    private String MessageDataForAppRecharge(ResultRecharge data,String templateId) {

        return "{  \"touser\":\"" + data.getOpenid() + "\",\n" +
                "           \"template_id\":\"" + templateId + "\",\n" +
                //     "           \"url\":\"" + url + "\",  \n" +
                "           \"data\":{\n" +
                "                   \"first\": {\n" +
                "                       \"value\":\"您的会员卡充值金额已实时到账，请查收" +"\",\n" +
                "                       \"color\":\"#173177\"\n" +
                "                   },\n" +
                "                   \"keyword1\":{\n" +
                "                       \"value\":\"" + data.getDate() + "\",\n" + //时间
                "                       \"color\":\"#173177\"\n" +
                "                   },\n" +
                "                   \"keyword2\": {\n" +
                "                       \"value\":\"" + data.getPrice() + "\",\n" + //金额
                "                        \"color\":\"#173177\"\n" +
                "                   },\n" +
                "                   \"keyword3\": {\n" +
                "                       \"value\":\"" + "现金" + "\",\n" + //方式
                "                        \"color\":\"#173177\"\n" +
                "                   },\n" +
                "                   \"keyword4\": {\n" +
                "                       \"value\":\"" + data.getGive() + "\",\n" + //充值赠送
                "                        \"color\":\"#173177\"\n" +
                "                   },\n" +
                "                   \"keyword5\": {\n" +
                "                       \"value\":\"" + data.getBalance() + "\",\n" + //当前余额
                "                        \"color\":\"#173177\"\n" +
                "                   },\n" +
                "                   \"remark\":{\n" +
                "                       \"value\":\"感谢您选购我们的产品和服务，您的满意是我们始终不变的追求！\",\n" +
                "                       \"color\":\"#173177\"\n" +
                "                   } }   }";
    }

    private String MessageDataForExpenditure(RetailData data, String templateId) {

        return "{  \"touser\":\"" + data.getOpenid() + "\",\n" +
                "           \"template_id\":\"" + templateId + "\",\n" +
                // "           \"url\":\"" + url + "\",  \n" +
                "           \"data\":{\n" +
                "                   \"first\": {\n" +
                "                       \"value\":\"尊敬的客户，您的本次服务已经完成" +"\",\n" +
                "                       \"color\":\"#173177\"\n" +
                "                   },\n" +
                "                   \"keyword1\":{\n" +
                "                       \"value\":\"" + data.getDate() + "\",\n" +
                "                       \"color\":\"#173177\"\n" +
                "                   },\n" +
                "                   \"keyword2\": {\n" +
                "                       \"value\":\"" + data.getStore() + "\",\n" +
                "                        \"color\":\"#173177\"\n" +
                "                   },\n" +
                "                   \"keyword3\": {\n" +
                "                       \"value\":\"" + data.getActual() + "\",\n" +
                "                        \"color\":\"#173177\"\n" +
                "                   },\n" +
                "                   \"keyword4\": {\n" +
                "                       \"value\":\"" + data.getAmount() + "\",\n" +
                "                        \"color\":\"#173177\"\n" +
                "                   },\n" +
                "                   \"keyword5\": {\n" +
                "                       \"value\":\"" + data.getIntegral() + "\",\n" +
                "                        \"color\":\"#173177\"\n" +
                "                   },\n" +
                "                   \"remark\":{\n" +
                "                       \"value\":\"感谢您对我们的支持，欢迎您下次光临！\",\n" +
                "                       \"color\":\"#173177\"\n" +
                "                   } }   }";
    }

    private String MessageDataForConsumption(String openid, String templateId, String date, String code, String url) {

        return "{  \"touser\":\"" + openid + "\",\n" +
                "           \"template_id\":\"" + templateId + "\",\n" +
                "           \"url\":\"" + url + "\",  \n" +
                "           \"data\":{\n" +
                "                   \"first\": {\n" +
                "                       \"value\":\"尊敬的客户，您的本次服务已经完成" +"\",\n" +
                "                       \"color\":\"#173177\"\n" +
                "                   },\n" +
                "                   \"keyword1\":{\n" +
                "                       \"value\":\"" + code + "\",\n" +
                "                       \"color\":\"#173177\"\n" +
                "                   },\n" +
                "                   \"keyword2\": {\n" +
                "                       \"value\":\"" + date + "\",\n" +
                "                        \"color\":\"#173177\"\n" +
                "                   },\n" +
                "                   \"remark\":{\n" +
                "                       \"value\":\"感谢您对我们的支持，您可以对本次服务的评价，欢迎您下次光临！\",\n" +
                "                       \"color\":\"#173177\"\n" +
                "                   } }   }";
    }

    private String MessageDataForNewUser(String openid, String templateId, String phone, String date, String integral,String appId) {

        return "{  \"touser\":\"" + openid + "\",\n" +
                "           \"template_id\":\"" + templateId + "\",\n" +
                "           \"miniprogram\":{\n" +
                "                       \"appid\":\""+appId+"\",\n" +
                "                       \"pagepath\":\"pages/start/start\"\n" +
                "                       },\n" +
                "           \"data\":{\n" +
                "                   \"first\": {\n" +
                "                       \"value\":\"绑定成功!" + integral.replace("-"," ") + "积分已到账,请查收\"," +
                "                       \"color\":\"#173177\"\n" +
                "                   },\n" +
                "                   \"keyword1\":{\n" +
                "                       \"value\":\"" + phone + "\",\n" +
                "                       \"color\":\"#173177\"\n" +
                "                   },\n" +
                "                   \"keyword2\": {\n" +
                "                       \"value\":\"" + date + "\",\n" +
                "                        \"color\":\"#173177\"\n" +
                "                   },\n" +
                "                   \"keyword3\": {\n" +
                "                       \"value\":\"" + integral + "\",\n" +
                "                        \"color\":\"#173177\"\n" +
                "                   },\n" +
                "                   \"remark\":{\n" +
                "                       \"value\":\"我们用心提升我们的服务,只为您100分满意！\",\n" +
                "                       \"color\":\"#173177\"\n" +
                "                   } }   }";
    }

    private String MessageDataForCoupon(String openid, String templateId, String code, String value, String name, String appId, String type) {

        return "{  \"touser\":\"" + openid + "\",\n" +
                "           \"template_id\":\"" + templateId + "\",\n" +
                "           \"miniprogram\":{\n" +
                "                       \"appid\":\""+appId+"\",\n" +
                "                       \"pagepath\":\"pages/member/ticketCode/ticketCode?code="+code+"\"\n" +
                "                       },\n" +
                "           \"data\":{\n" +
                "                   \"first\": {\n" +
                "                       \"value\":\"为您精选的礼券已到账,礼券编号" + code + "," + type + ":" + value + ",请查收\",\n" +
                "                       \"color\":\"#173177\"\n" +
                "                   },\n" +
                "                   \"keyword1\":{\n" +
                "                       \"value\":\"" + code + "\",\n" +
                "                       \"color\":\"#173177\"\n" +
                "                   },\n" +
                "                   \"keyword2\": {\n" +
                "                       \"value\":\"" + name + "\",\n" +
                "                        \"color\":\"#173177\"\n" +
                "                   },\n" +
                "                   \"remark\":{\n" +
                "                       \"value\":\"我们用心提升我们的服务,只为您100分满意！\",\n" +
                "                       \"color\":\"#173177\"\n" +
                "                   } }   }";
    }

    private String MessageDataForRecommend(String openid, String templateId, String phone, String date, String integral,String url) {

        return "{  \"touser\":\"" + openid + "\",\n" +
                "           \"template_id\":\"" + templateId + "\",\n" +
                "           \"url\":\"" + url + "\",  \n" +
                "           \"data\":{\n" +
                "                   \"first\": {\n" +
                "                       \"value\":\"推荐成功!" + integral.replace("-"," ") + "积分已到账,请查收\"," +
                "                       \"color\":\"#173177\"\n" +
                "                   },\n" +
                "                   \"keyword1\":{\n" +
                "                       \"value\":\"" + phone + "\",\n" +
                "                       \"color\":\"#173177\"\n" +
                "                   },\n" +
                "                   \"keyword2\": {\n" +
                "                       \"value\":\"" + date + "\",\n" +
                "                        \"color\":\"#173177\"\n" +
                "                   },\n" +
                "                   \"keyword3\": {\n" +
                "                       \"value\":\"" + integral + "\",\n" +
                "                        \"color\":\"#173177\"\n" +
                "                   },\n" +
                "                   \"remark\":{\n" +
                "                       \"value\":\"我们用心提升我们的服务,只为您100分满意！\",\n" +
                "                       \"color\":\"#173177\"\n" +
                "                   } }   }";
    }
}
